<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	//读取application.ini配置文件,并对view进行初始化的设置
	protected function _initView()
	{
		$options = $this->getOptions();
		$viewOptions = $options['resources']['view'];

		$view = new Zend_View($viewOptions);
		if (!empty($viewOptions['params'])) {
			foreach ($viewOptions['params'] as $key => $value) {
				$view->$key = $value;
			}
		}

		$view->env = $this->getEnvironment();
		$view->bootstrap = $this;
		$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
		$viewRenderer->setView($view);
		// 视图助手路径
		$view->addHelperPath($viewOptions['helperPath'],$viewOptions['helperPathPrefix']);

		return $view;
	}

	// 同理设置DB配置信息
	protected function _initDB()
	{
		$options = $this->getOption('resources');
		$options = $options['db'];

		$resources = $this->getPluginResource('db');
		$db = $resources->getDbAdapter();

		Zend_Db_Table::setDefaultAdapter($db);
		Zend_Registry::set('dbAdapter',$db);
		Zend_Registry::set('dbprefix',$options['params']['prefix']);

		return $db;
	}
}

